<template>
    <div>


      <p>用户名：<input type="text" v-model="name1"></p>
      <p>密码：<input type="password" v-model="pwd1"></p>
      <p><button @click="login">登录</button></p>
    </div>
</template>

<script>
    export default {
        name: "Login",
      data(){
          return{
            name:"",
            pwd:"",
            name1:"",
            pwd1:""

          }
      },
      methods:{
        login(){
            this.axios.patch("login/",{"name":this.name1,"pwd":this.pwd1})
            .then(resp=>{
              console.log(resp.data)
              if (resp.data.code==200){
                sessionStorage.setItem("name",this.name1)
                sessionStorage.setItem("token",resp.data.token)
                sessionStorage.setItem("counter",resp.data.counter)
                sessionStorage.setItem("id",resp.data.id)
                this.$router.push("/coach")
              }
            }).catch(err=>{
              console.log(err)
            })
          }

      },
      created() {

      }
    }
</script>

<style scoped>

</style>
